package com.huawei.appmarket.pkisign.internal.apk.v2;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import o.dma;
import o.dmb.a;
import o.dmm;

public abstract class V2SchemeVerifier {

    public static class SignatureNotFoundException extends Exception {
        public SignatureNotFoundException(String str) {
            super(str);
        }
    }

    public static dma<dmm, Long> ˎ(dmm o_dmm, a aVar) throws IOException, SignatureNotFoundException {
        long ॱ = aVar.ॱ();
        long ˊ = aVar.ˊ() + ॱ;
        long ˏ = aVar.ˏ();
        if (ˊ != ˏ) {
            throw new SignatureNotFoundException("ZIP Central Directory is not immediately followed by End of Central Directory. CD end: " + ˊ + ", EoCD start: " + ˏ);
        } else if (ॱ < 32) {
            throw new SignatureNotFoundException("APK too small for APK Signing Block. ZIP Central Directory offset: " + ॱ);
        } else {
            ByteBuffer ॱ2 = o_dmm.ॱ(ॱ - 24, 24);
            ॱ2.order(ByteOrder.LITTLE_ENDIAN);
            if (ॱ2.getLong(8) == 2334950737559900225L && ॱ2.getLong(16) == 3617552046287187010L) {
                ˏ = ॱ2.getLong(0);
                if (ˏ < ((long) ॱ2.capacity()) || ˏ > 2147483639) {
                    throw new SignatureNotFoundException("APK Signing Block size out of range: " + ˏ);
                }
                int i = (int) (8 + ˏ);
                ॱ -= (long) i;
                if (ॱ < 0) {
                    throw new SignatureNotFoundException("APK Signing Block offset out of range: " + ॱ);
                }
                ByteBuffer ॱ3 = o_dmm.ॱ(ॱ, 8);
                ॱ3.order(ByteOrder.LITTLE_ENDIAN);
                long j = ॱ3.getLong(0);
                if (j == ˏ) {
                    return dma.ˋ(o_dmm.ˊ(ॱ, (long) i), Long.valueOf(ॱ));
                }
                throw new SignatureNotFoundException("APK Signing Block sizes in header and footer do not match: " + j + " vs " + ˏ);
            }
            throw new SignatureNotFoundException("No APK Signing Block before ZIP Central Directory");
        }
    }
}
